package com.huike.clues.service.impl;


import com.huike.clues.domain.TbClue;
import com.huike.clues.domain.TbClueTrackRecord;
import com.huike.clues.mapper.TbClueMapper;
import com.huike.clues.mapper.TbClueTrackRecordMapper;
import com.huike.clues.service.ITbClueTrackRecordService;
import com.huike.common.core.domain.AjaxResult;
import com.huike.common.utils.DateUtils;
import com.huike.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 线索跟进记录Service业务层处理
 * @date 2022-04-22
 */
@Service
public class TbClueTrackRecordServiceImpl implements ITbClueTrackRecordService {
    @Autowired
    TbClueMapper tbClueMapper;
    @Autowired
    TbClueTrackRecordMapper tbClueTrackRecordMapper;

    /**
     * 新增线索更新记录
     * @param trackRecord 线索跟进记录
     * @return 结果
     */

    @Override
    public int insertTbClueTrackRecord(TbClueTrackRecord trackRecord) {
        trackRecord.setCreateTime(DateUtils.getNowDate());
        trackRecord.setCreateBy(SecurityUtils.getUsername());

        return tbClueTrackRecordMapper.insertTbClueTrackRecord(trackRecord);
    }

    @Override
    @Transactional
    public int insertTbClueTrackRecord(TbClue tbClue, TbClueTrackRecord trackRecord) {
        tbClueMapper.updateTbClue(tbClue);
        return tbClueTrackRecordMapper.insertTbClueTrackRecord(trackRecord);
    }

    /**
     * 查询线索跟进记录
     *
     * @param id 线索跟进记录ID
     * @return 线索跟进记录
     */
    @Override
    public TbClueTrackRecord selectTbClueTrackRecordById(Long id)
    {
        return tbClueTrackRecordMapper.selectTbClueTrackRecordById(id);
    }

    /**
     * 查询线索跟进记录列表
     *
     * @param tbClueTrackRecord 线索跟进记录
     * @return 线索跟进记录
     */
    @Override
    public List<TbClueTrackRecord> selectTbClueTrackRecordList(TbClueTrackRecord tbClueTrackRecord)
    {
        return tbClueTrackRecordMapper.selectTbClueTrackRecordList(tbClueTrackRecord);
    }

    /**
     * 根据线索id查询线索跟进记录
     */
    @Override
    public List<TbClueTrackRecord> selectTbClueTrackRecordList(Long clueId) {
        return tbClueTrackRecordMapper.selectTbClueTrackRecordListByClueId(clueId);
    }
}
